In [2]:
import theano.tensor as T
import theano
import numpy as np
import matplotlib.pyplot as plt
theano.config.compute_test_value = "ignore"
%matplotlib inline
import sys, os
sys.path.append("../gempy")
sys.path.append("../")
# Importing GeMpy modules
import gempy as gp
import pandas as pn
In [30]:
import sys
import gempy as gp
from GeoPhysics import GeoPhysicsPreprocessing
geo_data = gp.read_pickle('../Prototype Notebook/geo_data.pickle')
inter_data = gp.InterpolatorInput(geo_data, compile_theano=False)
gpp = GeoPhysicsPreprocessing(inter_data,300, [7.050000e+05,747000,6863000,6950000,-20000, 200], res_grav = [125, 85], n_cells =100)
print(gpp)
a = gpp.looping_z_decomp(1000)
In [3]:
a.shape
Out[3]:
In [4]:
62* 42
Out[4]:
In [31]:
for i in range(0,10,2):
print(i)
In [10]:
grav_real = pn.read_csv('Sst_grav_500.xyz', header=None, names = ['X', 'Y', 'N', 'G'], delim_whitespace=True)
In [14]:
grav_real.max(), grav_real.min()
Out[14]:
In [12]:
grav_real.shape, 125*85
Out[12]:
In [4]:
gpp.interp_data.extent_rescaled
Out[4]:
In [ ]:
grav_real
In [ ]:
85, 125, 51
696000 747000
6863000 6950000
:-50 ,18:
In [4]:
lith = np.load('sandstone_lith.npy')
In [31]:
np.place(lith, lith == 1, 2.61)
np.place(lith, lith == 2, 2.92)
np.place(lith, lith == 3, 3.1)
np.place(lith, lith == 4, 2.92)
np.place(lith, lith == 0, 2.61)
np.unique(lith)
Out[31]:
In [32]:
gr = gpp.compute_gravity(lith.reshape(-1,1)).sum(axis=0)
In [33]:
gr.max(), gr.min()
Out[33]:
In [15]:
gr.max(), gr.min()
Out[15]:
In [40]:
plt.contourf(grav_real['X'].reshape(125,85), grav_real['Y'].reshape(125,85), grav_real['G'].reshape(125,85), cmap='viridis',
)
plt.grid()
In [36]:
plt.imshow(gr.reshape(85,125), origin='bottom', cmap='viridis')
Out[36]:
In [29]:
plt.imshow(grav_real['G'].reshape(125,85), extent=[7.050000e+05,747000,6863000,6950000], origin='lower', cmap='viridis')
Out[29]:
In [28]:
7.050000e+05 -747000,6863000 -6950000
Out[28]:
In [18]:
plt.imshow(gr.reshape(25,25), origin='bottom', cmap='jet')
Out[18]:
In [ ]:
plt.imshow(gr.reshape(50,50), origin='bottom', cmap='viridis_r')
In [20]:
from scipy.constants import G
G
Out[20]:
In [ ]:
In [ ]:
In [57]:
for aa in range(2):
# print(aa, 'a')
for bb in range(2):
# print(bb, 'b')
for cc in range(2):
# print(cc, 'c')
# print('iter', aa, bb, cc)
print((-1) ** aa * (-1) ** bb * (-1) ** cc)
In [12]:
for aa in range(2):
print(aa)
In [ ]:
tz = tz - NewtG * (-1) ** aa * (-1) ** bb * (-1) ** cc * (
dx[:, aa] * np.log(dy[:, bb] + r) +
dy[:, bb] * np.log(dx[:, aa] + r) -
dz[:, cc] * np.arctan(dx[:, aa] * dy[:, bb] /
(dz[:, cc] * r)))
In [13]:
g = inter_data.data.grid.grid
In [45]:
dx= np.vstack((g[:, 0] - vox_size[0], g[:, 0] + vox_size[0])).T
dy = np.vstack((g[:, 1] - vox_size[1] , g[:, 1] + vox_size[1])).T
dz = np.stack((g[:, 2] - vox_size[2], g[:, 2] + vox_size[2])).T
In [58]:
mu = np.array([1,-1,-1,1,-1,1,1,-1])
In [41]:
dx_matrix = np.repeat(dx, 4, axis=1)
In [55]:
dy_matrix = np.tile(np.repeat(dy, 2, axis=1), (1,2)).shape
In [46]:
dz_matrix = np.tile(dz, (1,4))
dz_matrix.shape
Out[46]:
In [62]:
dx_matrix
Out[62]:
In [13]:
np.vstack?
In [ ]:
In [ ]:
In [15]:
x_extent = inter_data.extent_rescaled.iloc[1] - inter_data.extent_rescaled.iloc[0]
y_extent = inter_data.extent_rescaled.iloc[3] - inter_data.extent_rescaled.iloc[2]
z_extent = inter_data.extent_rescaled.iloc[5] - inter_data.extent_rescaled.iloc[4]
vox_size = np.array([x_extent, y_extent, z_extent])/geo_data.resolution
In [11]:
d_x
Out[11]:
In [ ]:
In [3]:
lith = np.load('sandstone_lith.npy')
In [2]:
geo_data = gp.read_pickle('geo_data.pickle')
In [3]:
inter_data = gp.InterpolatorInput(geo_data, compile_theano=False)
In [4]:
inter_data.__dict__
Out[4]:
In [11]:
k = inter_data.set_airbore_plane(2100, [5,5])
In [14]:
inter_data.extent_rescaled.iloc[0], inter_data.extent_rescaled
Out[14]:
In [89]:
z = 2100/inter_data.data.rescaling_factor
res_grav = np.array([5, 5])
In [90]:
g = np.meshgrid(np.linspace(geo_data.extent[0],
geo_data.extent[1], res_grav[0]),
np.linspace(geo_data.extent[2],
geo_data.extent[3], res_grav[1]))
h = np.ones(res_grav[0]*res_grav[1])*z
i = np.vstack(map(np.ravel, g))
k = np.vstack((i, h) ).T.astype("float32")
In [15]:
gr.astype('float32')
Out[15]:
In [4]:
lith.nbytes
Out[4]:
In [3]:
#lith = np.load('sandstone_lith.npy')
In [16]:
gr = inter_data.data.grid.grid.astype('float32')
In [17]:
x_1 = T.matrix()
x_2 = T.matrix()
sqd = T.sqrt(T.maximum(
(x_1**2).sum(1).reshape((x_1.shape[0], 1)) +
(x_2**2).sum(1).reshape((1, x_2.shape[0])) -
2 * x_1.dot(x_2.T), 0
))
eu = theano.function([x_1, x_2], sqd)
In [18]:
dist = eu(gr, k)
In [20]:
n1 = np.argsort(dist, axis=0)[:40,:]
In [21]:
n = np.indices((40,25))[1]
In [32]:
# Distances solved
dist[n1,n].shape, 40*25
Out[32]:
In [9]:
v = np.ones((40,1))
In [12]:
np.hstack((np.zeros((40,0)), v))
Out[12]:
In [33]:
sol = np.empty(0)
for i in range(25):
sol = np.append(sol, lith[n1[:,i]])
In [45]:
from scipy.constants import G
G?
In [38]:
sol.reshape(40,25)[:, 0]
Out[38]:
In [42]:
dist[n1,n][:, 0]
Out[42]:
In [69]:
np.count_nonzero(dist), dist.shape[0]*25
Out[69]:
In [71]:
k
Out[71]:
In [65]:
dist[:,0]
Out[65]:
In [53]:
b = np.ones((6,6))
b[[[2,4], 3,4],[[0,0],1,2]] = 9
b
In [ ]:
T.indice
In [9]:
_bool = dist>10000
In [68]:
np.unique(j)
Out[68]:
In [14]:
j = _bool * (lith+1)[:, np.newaxis]
In [15]:
np.unique(j), j.shape
Out[15]:
In [23]:
np.nonzero(j)[1]
Out[23]:
In [27]:
np.nonzero(j[:,0])
Out[27]:
In [35]:
T.nonzero_values(T.reshape(_bool, (-1,1))).eval()
Out[35]:
In [36]:
T.argmin?
In [80]:
dist_o = dist.argsort(axis=0)
In [81]:
dist_o
Out[81]:
In [89]:
s = dist_o[:200000, :]
In [83]:
np.save('select', s)
In [90]:
d = np.take(dist, s)
d.shape
Out[90]:
In [108]:
s
Out[108]:
In [102]:
lith_tile[[[0],[1]], s]
In [104]:
lith_tile[[[0],[1]], s]
In [ ]:
In [91]:
lith_tile = np.tile(lith, (25,1)).T
In [105]:
lith_select = np.take(np.ravel(lith_tile), s)
In [106]:
lith_tile.shape, s.shape
Out[106]:
In [93]:
{'DefaultBasement': 0,
'EarlyGranite': 1,
'SimpleBIF': 3,
'SimpleMafic1': 4,
'SimpleMafic2': 2}
Out[93]:
In [94]:
lith_select.shape
Out[94]:
In [107]:
np.unique(lith_select)
Out[107]:
In [61]:
np.place(lith_select, lith_select == 1, 2.61)
np.place(lith_select, lith_select == 2, 2.92)
np.place(lith_select, lith_select == 3, 3.1)
np.place(lith_select, lith_select == 4, 2.92)
np.place(lith_select, lith_select == 0, 2.61)
In [62]:
np.unique(lith_select)
Out[62]:
In [9]:
x_extent = geo_data.extent[1] - geo_data.extent[0]
y_extent = geo_data.extent[3] - geo_data.extent[2]
z_extent = geo_data.extent[5] - geo_data.extent[4]
In [11]:
x_extent = geo_data.extent[1] - geo_data.extent[0]
y_extent = geo_data.extent[3] - geo_data.extent[2]
z_extent = geo_data.extent[5] - geo_data.extent[4]
d_x = np.array([x_extent, y_extent, z_extent])/geo_data.resolution
In [14]:
vol = d_x[0]*d_x[1]*d_x[2]
d_x, vol
Out[14]:
In [59]:
Out[59]:
In [48]:
lith_tile.shape
Out[48]:
In [62]:
T.copy?
In [4]:
a = geo_data.grid.grid.reshape(50,50,50, 3)
In [6]:
b = a[:,:,0,:]
In [16]:
geo_data.grid.grid
Out[16]:
In [10]:
b = np.indices((50,50,50))
b []
In [7]:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xs = b[:,0]
ys = b[:,1]
zs = b[:,2]
ax.scatter(xs, ys, zs, )
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
In [ ]: